

var cboLoai_Change = function(param)
{
    if (param.value === "0")
    {
        $("#secHangSX").show();
    }
    else
    {
        $("#secHangSX").hide();
    }
};
function DangKy_Click()
{
    if ($('#term').is(':checked')) {
        var gioitinh = document.getElementById("cboGioiTinh");
        var loai = document.getElementById("cboLoai");
        var cboHangSX = $("#cboHangSX").val();
        var cboQuocGiaID = $("#cboQuocGiaID").val();
        var cboTinhID = $("#cboTinhID").val();

        DangKy([{name: 'GioiTinh', value: '' + gioitinh.value + ''},
            {name: 'Loai', value: '' + loai.value + ''},
            {name: 'QuocGiaID', value: '' + cboQuocGiaID + ''},
            {name: 'TinhID', value: '' + cboTinhID + ''},
            {name: 'HangSX', value: '' + cboHangSX + ''}
        ]);
    }else{
        alert('Please accept terms and condition.');
    }

}
function ThayDoiThongTinCaNhan_Click()
{

    var gioitinh = document.getElementById("cboGioiTinh");
    var loai = "";//document.getElementById("cboLoai");
    var cboHangSX = "";
    if ($("#txtLoaiXeBan_Profile").val() !== null && $("#txtLoaiXeBan_Profile").val().toString() !== "")
    {
        cboHangSX = $("#cboHangSX_Profile").val();
    }
    var cboQuocGiaID = $("#cboQuocGiaID").val();
    var cboTinhID = $("#cboTinhID").val();


    ThayDoiThongTinCaNhan([{name: 'GioiTinh', value: '' + gioitinh.value + ''},
        {name: 'Loai', value: '' + loai + ''},
        {name: 'QuocGiaID', value: '' + cboQuocGiaID + ''},
        {name: 'TinhID', value: '' + cboTinhID + ''},
        {name: 'HangSX', value: '' + cboHangSX + ''}
    ]);
}
function dangKyWithOpenId() {
    if ($('#term').is(':checked')) {
        var loai = $("#cboLoai").val();
        var cboHangSX = $("#cboHangSX").val();
        var cboQuocGiaID = $("#cboQuocGiaID").val();
        var cboTinhID = $("#cboTinhID").val();
        handlerRegistryWithOpenId([{name: 'Loai', value: '' + loai + ''},
            {name: 'QuocGiaID', value: '' + cboQuocGiaID + ''},
            {name: 'TinhID', value: '' + cboTinhID + ''},
            {name: 'HangSX', value: '' + cboHangSX + ''}
        ]);
    } else {
        alert('Please accept terms and condition.');
    }

}
function loginOpenId(type) {
    if (type === "Facebook") {
        handlerLoginOpenId([{name: 'Loai', value: '' + type + ''}]);
    }
}
function DangNhap_Click()
{
    var txtMa = document.getElementById("txtMa");
    var txtMatKhau = document.getElementById("txtMatKhau");

    DangNhap([{name: 'Ma', value: '' + txtMa.value + ''}, {name: 'MatKhau', value: '' + txtMatKhau.value + ''}]);
    return false;
}
function DangNhap_Enter(event)
{
    if (event.keyCode === 13)
    {
        var txtMa = document.getElementById("txtMa");
        var txtMatKhau = document.getElementById("txtMatKhau");

        DangNhap([{name: 'Ma', value: '' + txtMa.value + ''}, {name: 'MatKhau', value: '' + txtMatKhau.value + ''}]);
        return false;
    }
}
function cboQuocGiaID_Change_DangKy()
{

    var cboQuocGiaID = document.getElementById("cboQuocGiaID");

    cboQuocGiaID_Change([{name: 'QuocGiaID', value: '' + cboQuocGiaID.value + ''}]);

}
function cboQuocGiaID_Change_DangKy_1()
{

    var cboQuocGiaID = document.getElementById("cboQuocGiaID");
    //window.alert(cboQuocGiaID.value);
    cboQuocGiaID_Change1([{name: 'QuocGiaID', value: '' + cboQuocGiaID.value + ''}]);

}

function GetURLParameter(sParam)
{
    var sPageURL = window.location.search.substring(1);
    var sURLVariables = sPageURL.split('&');
    for (var i = 0; i < sURLVariables.length; i++) 
    {
        var sParameterName = sURLVariables[i].split('=');
        if (sParameterName[0] === sParam) 
        {
            return sParameterName[1];
        }
    }
    return null;
}

function cboQuocGiaID_Change_DangKy_5()
{
    var type=GetURLParameter("type");
    var value=GetURLParameter("value");
    
    var cboQuocGiaID = document.getElementById("cboQuocGiaID");
    var queryParameters = {}, queryString = location.search.substring(1),
    re = /([^&=]+)=([^&]*)/g, m;
 
    // Creates a map with the query string parameters
    while (m === re.exec(queryString)) {
        queryParameters[decodeURIComponent(m[1])] = decodeURIComponent(m[2]);
    }
  
    // Add new parameters or update existing ones
    
    queryParameters['QG'] = cboQuocGiaID.value;
     queryParameters['type'] = type;
    queryParameters['value'] = value;
   
    //queryParameters['existingParameter'] = 'new value';

    /*
     * Replace the query portion of the URL.
     * jQuery.param() -> create a serialized representation of an array or
     *     object, suitable for use in a URL query string or Ajax request.
     */
     location.search = $.param(queryParameters); // Causes page to reload
    //
//    if(GetURLParameter('QG')===null)
//        {
//            window.location.search = jQuery.query.set("QG", cboQuocGiaID.value);
//            //jQuery.param.querystring(window.location.href, 'QG=' + );
//        }
        //alert();
//    
//    cmdQuocGiaID_Change1([{name: 'QuocGiaID', value: '' + cboQuocGiaID.value + ''}]);
    //window.alert(cboQuocGiaID.value);
}

function ForgetPassword_Click()
{
    var txtEmail = document.getElementById("txtEmail");


    ForgetPassword([{name: 'Email', value: '' + txtEmail.value + ''}]);
    return false;
}


$(document).ready(function() {

    if ($("#cboLoai").val() === "0")
    {
        $("#secHangSX").show();
    }
    else
    {
        $("#secHangSX").hide();
    }

});

var updateSelectboxValue = function() {
    $('select[value]').each(function() {
        //alert(this.getAttribute("value"));
        //if(this.getAttribute("value")!==null && this.getAttribute("value").trim()!=="" && this.getAttribute("value").trim()!=="0")
        $(this).val(this.getAttribute("value"));
    });
    if ($("#cboLoai").val() === "0")
    {
        $("#secHangSX").show();
    }
    else
    {
        $("#secHangSX").hide();
    }
};

var phanTrangSearch = function(trang) {

    cmdPhanTrangSearch2([{name: 'pg', value: '' + trang + ''}]);

};